]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
texture-cache: Avoid creating unnecessary ClutterImages
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 24 Jan 2019 15:57:40 +0000 (13:57 -0200)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 24 Jan 2019 18:23:58 +0000 (16:23 -0200)
After loading the GdkPixbuf, StTextureCache unconditionally
creates a ClutterImage and, if it's not in the cache, add
it to the cache. That's a waste of resources when the image
is already committed to the texture cache.

Fix that by reusing the ClutterImage of the cache if it is
already there; otherwise, create a new ClutterImage as we
were previously doing.

src/st/st-texture-cache.c

index 337d81869ee1e247ede5a0d5a63dc5c449c7fab2..d0c49960b23f56c9d399e19926fc03622db48fcf 100644 (file)
@@ -528,20 +528,30 @@ finish_texture_load (AsyncTextureLoadData *data,
   if (pixbuf == NULL)
     goto out;
 
-  image = pixbuf_to_clutter_image (pixbuf);
-  if (!image)
-    goto out;
-
   if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
     {
-      gpointer orig_key, value;
+      gpointer orig_key = NULL, value = NULL;
 
       if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
                                          &orig_key, &value))
         {
+          image = pixbuf_to_clutter_image (pixbuf);
+          if (!image)
+            goto out;
+
           g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
                                g_object_ref (image));
         }
+      else
+        {
+          image = g_object_ref (value);
+        }
+    }
+  else
+    {
+      image = pixbuf_to_clutter_image (pixbuf);
+      if (!image)
+        goto out;
     }
 
   for (iter = data->actors; iter; iter = iter->next)